package com.syh.jn.scm.service.impl.supplier.base;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.supplier.entity.base.SupplierAddress;
import com.syh.jn.scm.domain.supplier.repository.base.SupplierAddressRepository;
import com.syh.jn.scm.dto.supplier.base.supplierAddress.SupplierAddressMto;
import com.syh.jn.scm.dto.supplier.base.supplierAddress.SupplierAddressSto;
import com.syh.jn.scm.dto.supplier.base.supplierAddress.SupplierAddressVo;
import com.syh.jn.scm.service.api.supplier.base.SupplierAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务商地址管理
 */
@Service
@Transactional
public class SupplierAddressServiceImpl extends AbstractServiceImpl<SupplierAddressSto, SupplierAddressMto, SupplierAddressVo, SupplierAddress, Long> implements SupplierAddressService {
  @Autowired
  private SupplierAddressRepository supplierAddressRepository;

  @Override
  protected AggregateRepository<SupplierAddress, Long> getAggregateRepository() {
    return supplierAddressRepository;
  }
  /**
   * 新增地址
   *
   * @param sto
   * @return
   */
  @Override
  public Long save(SupplierAddressSto sto) {
    SupplierAddress supplierAddress = new SupplierAddress(sto);
    return supplierAddressRepository.add(supplierAddress);
  }

  /**
   * 编辑地址
   *
   * @param mto
   */
  @Override
  public void update(SupplierAddressMto mto) {
    SupplierAddress supplierAddress = supplierAddressRepository.getById(mto.getId());
    supplierAddress.modify(mto);
    supplierAddressRepository.update(supplierAddress);
  }

  /**
   * 删除地址
   *
   * @param id
   */
  @Override
  public void delete(Long id) {
    SupplierAddress supplierAddress = supplierAddressRepository.getById(id);
    supplierAddress.destroy();
    supplierAddressRepository.remove(supplierAddress);
  }
}
